package com.lfnyxy.service.imp;


import com.lfnyxy.dao.ClientTypeDao;
import com.lfnyxy.entity.ClientTypeEntity;
import com.lfnyxy.query.ClientTypeQuery;
import com.lfnyxy.service.ClientTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClientTypeServiceImp implements ClientTypeService {
    @Autowired
    public ClientTypeDao clientTypeDao;

    public int CreateItem(ClientTypeEntity entity) {
        if (entity != null) {
            if (CheckIsExist(entity)) {
                return -1;
            }
            return clientTypeDao.CreateItem(entity);
        } else {
            return 0;
        }
    }

    public int UpdateItem(ClientTypeEntity entity) {
        if (entity != null) {
            if (CheckIsExist(entity)) {
                return -1;
            }
            return clientTypeDao.UpdateItem(entity);
        } else {
            return 0;
        }
    }

    public List<ClientTypeEntity> QueryPageList(ClientTypeQuery query) {
        int count = clientTypeDao.QueryPageListCount(query);
        query.setTotal(count);
        if (count > 0) {
            return clientTypeDao.QueryPageList(query);
        }
        return null;
    }

    public List<ClientTypeEntity> QueryAll() {
        return clientTypeDao.QueryAll();
    }

    public ClientTypeEntity QueryItem(int Id) {
        if (Id > 0) {
            return clientTypeDao.QueryItem(Id);
        } else {
            return null;
        }
    }

    public int DeleteItem(int Id) {
        if (Id > 0) {
            return clientTypeDao.DeleteItem(Id);
        } else {
            return 0;
        }
    }

    private boolean CheckIsExist(ClientTypeEntity entity) {
        if (entity != null) {
            return clientTypeDao.CheckIsExist(entity) > 0;
        } else {
            return false;
        }
    }
}